home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest_04.lha / src / sun / parallel.h
Encoding:
C/C++ Source or Header  |  1989-08-08  |  3.7 KB  |  157 lines

  1. #ifndef _PARALLEL_H
  2. #define _PARALLEL_H
  3. /* $Copyright:    $
  4.  * Copyright (c) 1984, 1985, 1986 Sequent Computer Systems, Inc.
  5.  * All rights reserved
  6.  *  
  7.  * This software is furnished under a license and may be used
  8.  * only in accordance with the terms of that license and with the
  9.  * inclusion of the above copyright notice.   This software may not
  10.  * be provided or otherwise made available to, or used by, any
  11.  * other person.  No title to or ownership of the software is
  12.  * hereby transferred.
  13.  */
  14.  
  15. // $Header: /crg2/bruces2/rbk/C++/Presto/src/RCS/parallel.h,
  16. /* v 1.2 88/03/24 09:52:47 rbk Exp $                
  17.  *
  18.  * parallel.h
  19.  *    Definitions for use in parallel, shared-memory programs.
  20.  */
  21.  
  22. /* $Log:    parallel.h,v $
  23.  * Revision 1.2  88/03/24  09:52:47  rbk
  24.  * #ifdef ns32000 around ALM fuss.  Can't use system version of this file
  25.  * since C++ doesn't understand asm-functions yet.
  26.  * 
  27.  * Revision 1.1  88/03/22  15:26:42  rbk
  28.  * Initial revision
  29.  * 
  30.  */
  31.  
  32. /*
  33.  * A "lock" is a byte of memory, initialized to zero (unlocked).
  34.  */
  35.  
  36. typedef unsigned char    slock_t;        /* 's' for "spin"-lock */
  37.  
  38. #define    L_UNLOCKED    0
  39. #define    L_LOCKED    1
  40.  
  41. /*
  42.  * Was a conditional lock request granted (L_SUCCESS) or denied (L_FAILED)
  43.  */
  44. #define L_FAILED    0
  45. #define L_SUCCESS    1
  46.  
  47. /*
  48.  * A "barrier" allows multiple processes to synchronize by having
  49.  * all of them exit the barrier construct simultaneously.
  50.  *
  51.  * This version assumes <= 255 processes, fits in one 4-byte integer,
  52.  * and is based on spin-locks.
  53.  */
  54.  
  55. typedef struct    {
  56.     slock_t        b_mutex;    /* mutual exclusion */
  57.     unsigned char    b_limit;    /* number participants */
  58.     unsigned char    b_count;    /* state counter */
  59.     unsigned char    b_useno;    /* current use # (state flag) */
  60. } sbarrier_t;                /* 's' for "spin"-barrier */
  61.  
  62.  
  63. #ifndef c_plusplus
  64. /*
  65.  * Other useful declarations.
  66.  */
  67.  
  68. extern    char    *sbrk(), *shsbrk();
  69. extern    char    *shmalloc();
  70.  
  71. #endif
  72.  
  73. #if    (ns32000 || mc68020)
  74. /*
  75.  * ALM_HASH() is used to hash an address to an ALM offset.
  76.  */
  77.  
  78. #define    ALM_HASH(x)    ((int)(&(x)) & (0xFF << 2))
  79. #ifdef    ns32000
  80.  
  81. /*
  82.  * S_LOCK() and S_UNLOCK() provide in-line access to locks for C-programs;
  83.  * these can be used in time-criticial situations, at a cost in code size.
  84.  *
  85.  * CAREFUL using S_LOCK(): cc -O -i doesn't do S_LOCK(&x) correctly; need
  86.  * to pass pointer to lock, not address of lock.
  87.  */
  88.  
  89. #define    S_LOCK(lp)    { \
  90.     register char    *lock_alm = &_alm_base[ALM_HASH(*(lp))]; \
  91.     for (;;) { \
  92.         /* Wait for lock to be available */ \
  93.         while (*(lp) == L_LOCKED) \
  94.             continue; \
  95.         /* Grab ALM gate for atomic access to lock */ \
  96.         while (*lock_alm & ALM_LOCKED) \
  97.             continue; \
  98.         /* Can race with others trying to get the lock */ \
  99.         if (*(lp) == L_UNLOCKED) { \
  100.             /* No race (or won it) -- grab the lock */ \
  101.             *(lp) = L_LOCKED; \
  102.             *lock_alm = ALM_UNLOCKED; \
  103.             break; \
  104.         } \
  105.         /* Lost race, try again */ \
  106.         *lock_alm = ALM_UNLOCKED; \
  107.     } \
  108. }
  109. #endif ns32000
  110. #define    S_UNLOCK(lp)    (*(lp) = L_UNLOCKED)
  111.  
  112. /*
  113.  * Various implementation dependent parameters.
  114.  */
  115.  
  116. #define    NBALM        4        /* number bytes per ALM */
  117. #define    ALMSIZE        1024        /* size of our portion of ALMs */
  118.  
  119. #define    ALM_UNLOCKED    0
  120. #define    ALM_LOCKED    1
  121.  
  122. #define    NALMDEVS    64        /* # different ALM's to try for */
  123.  
  124. #define    ADDR_RND    0x800        /* boundary round (text/data/end) */
  125.  
  126. #endif    (ns32000|mc68020)
  127.  
  128. /*
  129.  * Convenience definitions.
  130.  */
  131.  
  132. #ifndef    NULL
  133. #define    NULL        0
  134. #endif
  135.  
  136. /*
  137.  * Various globally used data.
  138.  */
  139.  
  140. extern    int    errno;
  141.  
  142. extern    int    _shm_fd;        /* fd for shared data mapped file */
  143. #ifdef  mc68020
  144. char alm_base[ALMSIZE];
  145. #endif  mc68020
  146. #ifdef    ns32000
  147. extern    char    *_alm_base;        /* virt addr of mapped ALM's */
  148. #endif    ns32000
  149. extern    int    _pgoff;            /* getpagesize() - 1 */
  150.  
  151. /*
  152.  * PGRND() rounds up a value to next page boundary.
  153.  */
  154.  
  155. #define    PGRND(x)    (char *) (((int)(x) + _pgoff) & ~_pgoff)
  156. #endif _PARALLEL_H
  157.